/**
 * Copyright (C)  2011  chen wei hua.
 * Permission is granted to copy, distribute and/or modify this document
 * under the terms of the GNU Free Documentation License, Version 2.0
 * or any later version published by the Free Software Foundation;
 * with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
 * A copy of the license is included in the section entitled "GNU Free Documentation License".
 */
package com.javaeye.store.dto;

import java.util.HashSet;
import java.util.Set;

import com.javaeye.common.dto.DTO;

public class Materials implements DTO {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 2844773041688424970L;

	private int id;
	
	private String code;
	
	private MaterialsCategory rootCategory;
	
	private MaterialsCategory category;
	
	private String name;
	
	private String type;
	
	private String supplier;
	
	private String property;
	
	private String units;
	
	private float minNumber;
	
	private float maxNumber;
	
	private float number;
	
	private Float waitNumber;
	
	private Float defectiveNumber;
	
	private Set<MaterialsSKUDetail> skuDetails;
	
	private Set<MaterialsFieldCustom> customFields;
	
	private int inuse;
	
	public Materials() {
		rootCategory = new MaterialsCategory();
		category = new MaterialsCategory();
		skuDetails = new HashSet<MaterialsSKUDetail>();
		customFields = new HashSet<MaterialsFieldCustom>();
	}
	
	public boolean isInUse() {
		return inuse == 1;
	}
	
	public void addCustomField(MaterialsFieldCustom field) {
		field.setMaterials(this);
		customFields.add(field);
	}
	
	public void removeCustomField(MaterialsFieldCustom field) {
		customFields.remove(field);
		field.setMaterials(null);
	}
	
	public void addSkuDetail(MaterialsSKUDetail detail) {
		detail.setMaterials(this);
		skuDetails.add(detail);
	}
	
	public void removeSkuDetail(MaterialsSKUDetail detail) {
		skuDetails.remove(detail);
		detail.setMaterials(null);
	}
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getCode() {
		StringBuilder sb = new StringBuilder();
		sb.append(rootCategory.getId());
		sb.append(".");
		sb.append(category.getId());
		sb.append(".");
		sb.append(name);
		sb.append(".");
		sb.append(type);
		code = sb.toString();
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public MaterialsCategory getCategory() {
		return category;
	}

	public void setCategory(MaterialsCategory category) {
		this.category = category;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getProperty() {
		return property;
	}

	public void setProperty(String property) {
		this.property = property;
	}

	public String getUnits() {
		return units;
	}

	public void setUnits(String units) {
		this.units = units;
	}

	public float getNumber() {
		return number;
	}

	public void setNumber(float number) {
		this.number = number;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getSupplier() {
		return supplier;
	}

	public void setSupplier(String supplier) {
		this.supplier = supplier;
	}

	public float getMinNumber() {
		return minNumber;
	}

	public void setMinNumber(float minNumber) {
		this.minNumber = minNumber;
	}

	public float getMaxNumber() {
		return maxNumber;
	}

	public void setMaxNumber(float maxNumber) {
		this.maxNumber = maxNumber;
	}

	public void setRootCategory(MaterialsCategory rootCategory) {
		this.rootCategory = rootCategory;
	}

	public MaterialsCategory getRootCategory() {
		return rootCategory;
	}

	public Float getWaitNumber() {
		return (waitNumber==null) ? 0 : waitNumber;
	}

	public void setWaitNumber(Float waitNumber) {
		this.waitNumber = waitNumber;
	}

	public Float getDefectiveNumber() {
		return (defectiveNumber==null) ? 0 : defectiveNumber;
	}

	public void setDefectiveNumber(Float defectiveNumber) {
		this.defectiveNumber = defectiveNumber;
	}
	
	public void setSkuDetails(Set<MaterialsSKUDetail> skuDetails) {
		this.skuDetails = skuDetails;
	}

	public Set<MaterialsSKUDetail> getSkuDetails() {
		return skuDetails;
	}

	public void setCustomFields(Set<MaterialsFieldCustom> customFields) {
		this.customFields = customFields;
	}

	public Set<MaterialsFieldCustom> getCustomFields() {
		return customFields;
	}

	public void setInuse(int inuse) {
		this.inuse = inuse;
	}

	public int getInuse() {
		return inuse;
	}
}
